const Storage = require('./storage');

class Auth {
  static checkTokenExpiration(token) {
    if (!token) return true;
    
    try {
      const payload = JSON.parse(atob(token.split('.')[1]));
      const now = Math.floor(Date.now() / 1000);
      // 提前5分钟判断为过期
      return payload.exp < now + 300;
    } catch (e) {
      return true;
    }
  }
  
  static getTokenPayload(token) {
    if (!token) return null;
    
    try {
      return JSON.parse(atob(token.split('.')[1]));
    } catch (e) {
      return null;
    }
  }
}

module.exports = Auth;